<template>
  <div class="authing">
    授权中...
  </div>
</template>

<script>
export default {
    name:"Auth",
    async created(){
        let redirectUrl = this.$route.query.redirect;
        if(!this.$route.query.code){ //
            let url = location.origin+"/auth?redirect="+encodeURIComponent(redirectUrl)
            
            location.href = "http://localhost/api/wechat/redirect?url="+encodeURIComponent(url);
            return;
        }
        
        this.$store.dispatch('user/login', {
            code: this.$route.query.code
         }).then(() => {
            let r = new URL(redirectUrl);
            this.$router.push(r.pathname+r.search+r.hash);
        })
        .catch(() => {

        })

        
    }
}
</script>

<style>
    .authing{
        text-align:center;
    }
</style>